import Mock from 'mockjs2'
import {builder, getQueryParameters} from "@/mock/util";

const totalCount = 100

const permissionList = (options) => {
	console.log('org mock: permission list')
	console.log(options)
	const parameters = getQueryParameters(options)
	const page = parseInt(parameters.page)
	const pageSize = parseInt(parameters.pageSize)
	const pages = Math.ceil(totalCount / pageSize)
	const data = [
		{"id":1,"orgId":1,"datasourceId":7,"datasourceName":"人保微盟","config":"{\n" +
				"\t\t\"index\": 0, \n" +
				"\t\t\"rules\": [\n" +
				"\t\t\t{\"index\": 0, \"value\": \"Android\", \"values\": [], \"operator\": \"contain\", \"property\": \"events.os_version\"},\n" +
				"\t\t\t{\"index\": 1, \"value\": \"\", \"values\": [], \"operator\": \"isTrue\", \"property\": \"events.login_status\"}, \n" +
				"\t\t\t{\"index\": 2, \"value\": \"中国电信\", \"values\": [], \"operator\": \"contain\", \"property\": \"events.carrier_name\"}], \n" +
				"\t\t\"filters\": [],\n" +
				"\t\t\"condition\": \"AND\"\n" +
				"\t}","analysisProject":"2d3f59f847f44745b9636a8f4fdd4582","remark":"1","type":0,"createdAt":"2021-09-15 15:24:15","updatedAt":"2021-09-15 15:24:18"},
		{"id":2,"orgId":1,"datasourceId":6,"datasourceName":"impala","config":"","analysisProject":"","remark":"2","type":1,"createdAt":"2021-09-15 15:24:15","updatedAt":"2021-09-15 15:24:18"},
		{"id":3,"orgId":1,"datasourceId":4,"datasourceName":"app","config":"","analysisProject":"2d3f59f847f44745b9636a8f4fdd4582","remark":"3","type":0,"createdAt":"2021-09-15 15:24:15","updatedAt":"2021-09-15 15:24:18"},
		{"id":4,"orgId":1,"datasourceId":3,"datasourceName":"微信","config":"","analysisProject":"2d3f59f847f44745b9636a8f4fdd4582","remark":"4","type":0,"createdAt":"2021-09-15 15:24:15","updatedAt":"2021-09-15 15:24:18"}
	]
	const result = builder({
		total: 7,
		size: 10,
		pages: 1,
		current: 1,
		data: data,
	})
	console.log(result)
	return result
}


const addField = (options) => {
	console.log(options)

	return builder()
}

const updateField = (options) => {
	console.log(options)
	return builder()
}

const deleteDatasource = (options) => {
	console.log('org mock: delete data source')
	console.log(options)
	return builder()
}



Mock.mock(/^.*?\/org\/\w*\/datasource.*$/, 'get', permissionList)
Mock.mock(/^.*?\/org\/\w*\/datasource\/.*$/, 'post', addField)
Mock.mock(/^.*?\/org\/\w*\/datasource\/.*$/, 'put', updateField)
Mock.mock(/^.*?\/org\/\w*\/datasource\/.*$/, 'delete', deleteDatasource)
